package com.icode.core.dto.manager;

import com.icode.core.dto.house.HouseInfoDTO;
import com.icode.core.dto.house.HouseWeekDTO;
import com.icode.core.dto.house.StartAndEndTimeDTO;
import com.icode.core.model.manage.Reserve;
import com.icode.core.model.manage.ReserveTime;
import com.icode.core.shared.JodaTimeUtils;
import org.hibernate.validator.constraints.NotEmpty;

import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: xianfei
 * Date: 15-4-14
 * Time: 下午3:43
 * To change this template use File | Settings | File Templates.
 */
public class ReserveDTO {

    private String guid;
    @NotEmpty(message = "请填写入住人!")
    private String occupancyName;
    private String IDCard;
    private String phoneNum;
    private String email;
    private String peers;
    private String remarks;
    @NotEmpty(message = "请选择性别!")
    private String gender;
    private String houseBaseName;
    private String status;
    private HouseWeekDTO houseWeekDTO;
    private HouseInfoDTO houseInfoDTO;
    private String buyNum; //购买的份数
    private String houseWeekGuid;
    private String houseInfoGuid;
    private String reserveTimes;
    private String reserveDate;

    private String checkInDate;
    private String leaveDate;

    private List<ReserveTimeDTO> reserveTimeDTOs;

    public ReserveDTO() {
    }

    public ReserveDTO(String guid, String occupancyName, String IDCard, String phoneNum, String email, String houseBaseName, String gender, String peers,
                      String remarks, String status, HouseWeekDTO houseWeekDTO, HouseInfoDTO houseInfoDTO, String buyNum, String reserveDate,List<ReserveTimeDTO> reserveTimeDTOs) {
        this.guid = guid;
        this.occupancyName = occupancyName;
        this.IDCard = IDCard;
        this.phoneNum = phoneNum;
        this.email = email;
        this.houseBaseName = houseBaseName;
        this.peers = peers;
        this.remarks = remarks;
        this.gender = gender;
        this.status = status;
        this.houseWeekDTO = houseWeekDTO;
        this.houseInfoDTO = houseInfoDTO;
        this.buyNum = buyNum;
        this.reserveDate = reserveDate;
        this.reserveTimeDTOs = reserveTimeDTOs;
    }

    public ReserveDTO(String houseBaseName, HouseInfoDTO houseInfoDTO, String checkInDate, String leaveDate) {
        this.guid = guid;
        this.houseBaseName = houseBaseName;
        this.status = status;
        this.houseInfoDTO = houseInfoDTO;
        this.checkInDate = checkInDate;
        this.leaveDate = leaveDate;
    }

    public static ReserveDTO toDTO(Reserve reserve) {
//        HouseWeekDTO houseWeekDTO = new HouseWeekDTO(reserve.houseWeek().guid(), reserve.houseWeek().name(), reserve.houseWeek().price());
        HouseWeekDTO houseWeekDTO = HouseWeekDTO.toDTO(reserve.houseWeek());
        List<String> imgGuids = new ArrayList<>();
        imgGuids.add(reserve.houseInfo().houseInfoImages().get(0).image().guid());
        HouseInfoDTO houseInfoDTO = new HouseInfoDTO(reserve.houseInfo().guid(), reserve.houseInfo().baseInfo().houseName(), imgGuids);
        String occupancyName = reserve.occupancyName();
        String IDCard = reserve.iDCard();
        String phoneNum = reserve.phoneNum();
        String email = reserve.email();
        String title = reserve.houseInfo().buildingType().houseBase().title();
        String gender = reserve.gender();
        String peers = reserve.peers();
        String remarks = reserve.remarks();
        String status = reserve.status();
        String buyNum = reserve.buyNum();
        String date = reserve.date();
        List<ReserveTimeDTO> reserveTimeDTOs = ReserveTimeDTO.toDTOs(reserve.reserveTimes());
        return new ReserveDTO(reserve.guid(), occupancyName, IDCard, phoneNum, email, title, gender, peers, remarks,
                status, houseWeekDTO, houseInfoDTO, buyNum, date,reserveTimeDTOs);
    }

    public static List<ReserveDTO> toDTOs(List<Reserve> reserves) {
        List<ReserveDTO> reserveDTOs = new ArrayList<>();
        for (Reserve r : reserves) {
            ReserveDTO reserveDTO = toDTO(r);
            reserveDTOs.add(reserveDTO);
        }
        return reserveDTOs;
    }

    public static Reserve toReserve(ReserveDTO reserveDTO) {
        Reserve reserve = new Reserve(reserveDTO.getOccupancyName(), reserveDTO.getIDCard(), reserveDTO.getPhoneNum(),
                reserveDTO.getEmail(), reserveDTO.getGender(), reserveDTO.getPeers(), reserveDTO.getRemarks(), reserveDTO.getStatus(),
                reserveDTO.getBuyNum(), JodaTimeUtils.getTime("yyyy-MM-dd"));
        return reserve;
    }

    public void initReserveDTO(HouseInfoDTO houseInfoDTO, HouseWeekDTO houseWeekDTO) {
        this.houseInfoDTO = houseInfoDTO;
        this.houseWeekDTO = houseWeekDTO;
    }

    public void setGuid(String guid) {
        this.guid = guid;
    }

    public String getBuyNum() {
        return buyNum;
    }

    public void setBuyNum(String buyNum) {
        this.buyNum = buyNum;
    }

    public String getReserveTimes() {
        return reserveTimes;
    }

    public void setReserveTimes(String reserveTimes) {
        this.reserveTimes = reserveTimes;
    }

    public void setOccupancyName(String occupancyName) {
        this.occupancyName = occupancyName;
    }

    public void setPeers(String peers) {
        this.peers = peers;
    }

    public void setRemarks(String remarks) {
        this.remarks = remarks;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public void setHouseWeekGuid(String houseWeekGuid) {
        this.houseWeekGuid = houseWeekGuid;
    }

    public void setHouseInfoGuid(String houseInfoGuid) {
        this.houseInfoGuid = houseInfoGuid;
    }

    public String getHouseWeekGuid() {

        return houseWeekGuid;
    }

    public String getHouseInfoGuid() {
        return houseInfoGuid;
    }

    public String getStatus() {

        return status;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }

    public String getPeers() {

        return peers;
    }

    public String getRemarks() {
        return remarks;
    }

    public String getGender() {
        return gender;
    }

    public void setHouseWeekDTO(HouseWeekDTO houseWeekDTO) {
        this.houseWeekDTO = houseWeekDTO;
    }

    public void setHouseInfoDTO(HouseInfoDTO houseInfoDTO) {
        this.houseInfoDTO = houseInfoDTO;
    }

    public HouseWeekDTO getHouseWeekDTO() {
        return houseWeekDTO;
    }

    public void setHouseBaseName(String houseBaseName) {
        this.houseBaseName = houseBaseName;
    }

    public String getHouseBaseName() {

        return houseBaseName;
    }

    public HouseInfoDTO getHouseInfoDTO() {
        return houseInfoDTO;
    }

    public void setIDCard(String IDCard) {
        this.IDCard = IDCard;
    }

    public void setPhoneNum(String phoneNum) {
        this.phoneNum = phoneNum;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getGuid() {
        return guid;
    }

    public String getOccupancyName() {
        return occupancyName;
    }

    public String getIDCard() {
        return IDCard;
    }

    public String getPhoneNum() {
        return phoneNum;
    }

    public String getEmail() {
        return email;
    }

    public String getReserveDate() {
        return reserveDate;
    }

    public void setReserveDate(String reserveDate) {
        this.reserveDate = reserveDate;
    }

    public String getCheckInDate() {
        return checkInDate;
    }

    public void setCheckInDate(String checkInDate) {
        this.checkInDate = checkInDate;
    }

    public String getLeaveDate() {
        return leaveDate;
    }

    public void setLeaveDate(String leaveDate) {
        this.leaveDate = leaveDate;
    }

    public List<ReserveTimeDTO> getReserveTimeDTOs() {
        return reserveTimeDTOs;
    }

    public void setReserveTimeDTOs(List<ReserveTimeDTO> reserveTimeDTOs) {
        this.reserveTimeDTOs = reserveTimeDTOs;
    }
}
